
package ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.widget.CheckBox;

import net.ck.hzq.R;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import Bean.FindAddressBean;
import base.BaseViewHolder;
import base.SuperBaseAdapter;
import coom.Constants;
import event.DefaultAddressEvent;
import event.DeleteAddressEvent;
import ui.activity.mine.NewAddressAct;
import util.ToastUtils;


/**
 * 历史收益适配器
 * Created by chenjian on 19/2/27.
 */
public class ManagerAddressAdapter extends SuperBaseAdapter<FindAddressBean.DataBean.ItemsBean> {

    List<FindAddressBean.DataBean.ItemsBean> mData = new ArrayList<>();
    Context mContext;

    public ManagerAddressAdapter(Context context, List<FindAddressBean.DataBean.ItemsBean> data) {
        super(context, data);
        mContext = context;
        mData = data;
    }

    @Override
    protected void convert(BaseViewHolder holder, final FindAddressBean.DataBean.ItemsBean item, final int position) {
        holder.setText(R.id.manager_txt_1, "收货人：" + item.getName()).setText(R.id.manager_txt_2, item.getPhone())
                .setText(R.id.manager_txt_3, item.getAddress());
        CheckBox checkBox = holder.getView(R.id.manager_chexckbox);
        checkBox.setChecked(item.getIsDefault() == 1);
        checkBox.setOnClickListener(v -> {
            if (item.getIsDefault() == 1) {
                ToastUtils.shortToast("该地址已经是默认地址");
                checkBox.setChecked(true);
                return;
            }
            EventBus.getDefault().post(new DefaultAddressEvent(mData.get(position).getId(), position));
        });
        holder.getView(R.id.manager_txt_5).setOnClickListener(v -> {
            Intent intent = new Intent(mContext, NewAddressAct.class);
            intent.putExtra(Constants.KEY, item);
            mContext.startActivity(intent);
        });
        holder.getView(R.id.manager_txt_4).setOnClickListener(v -> EventBus.getDefault().post(new DeleteAddressEvent(mData.get(position).getId(), position)));

    }


    @Override
    protected int getItemViewLayoutId(int position, FindAddressBean.DataBean.ItemsBean item) {
        return R.layout.listviewmanageraddress_item;
    }

}
